package com.hfzy.ihk.common.web.enums;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA 14.
 * User: Liutao
 * Date: 2015/4/3
 * Time:  15:07
 * 错误信息对照码n
 */
public enum LoginErrorMsgEnum {
    USER_NAME_NULL("USER_NAME_NULL", "用户名不能为空"),
    PASSWORD_NULL("USER_NAME_NULL", "密码不能为空"),
    VALIDATE_CODE_NULL("VALIDATE_CODE_NULL", "密码不能为空"),
    SUCCESS("SUCCESS", "成功"),
    LOGIN_FAIL("LOGIN_FAIL", "登录失败"),
    USER_NOT_FIND("USER_NOT_FIND", "用户不存在"),
    PASSWORD_NOT_FIND("PASSWORD_NOT_FIND", "密码不正确"),
    VALIDATE_CODE_ERROR("VALIDATE_CODE_ERROR", "验证码错误");


    private LoginErrorMsgEnum(String value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    private String value;

    private String desc;

    public String getDesc() {
        return desc;
    }

    public String toStr() {
        return value;
    }

    private static Map<String, LoginErrorMsgEnum> map = new HashMap<String, LoginErrorMsgEnum>();

    static {
        for (LoginErrorMsgEnum value : LoginErrorMsgEnum.values())
            map.put(value.toStr(), value);
    }

    public static LoginErrorMsgEnum fromStr(String name) {
        LoginErrorMsgEnum ret = map.get(name);
        if (ret != null)
            return ret;
        else
            throw new IllegalArgumentException("No enum const "
                    + LoginErrorMsgEnum.class + "." + name);
    }

    private static Map<String, LoginErrorMsgEnum> descMap = new HashMap<String, LoginErrorMsgEnum>();

    static {
        for (LoginErrorMsgEnum value : LoginErrorMsgEnum.values())
            descMap.put(value.getDesc(), value);
    }

    public static LoginErrorMsgEnum fromDesc(String desc) {
        LoginErrorMsgEnum ret = descMap.get(desc);
        if (ret != null)
            return ret;
        else
            throw new IllegalArgumentException("No enum const " + LoginErrorMsgEnum.class
                    + "." + desc);
    }

    private static Map<String, String> keyMap = new HashMap<String, String>();

    static {
        for (LoginErrorMsgEnum value : LoginErrorMsgEnum.values())
            keyMap.put(value.toStr(), value.getDesc());
    }

    public static String fromKey(String key) {
        String ret = keyMap.get(key);
        if (ret != null)
            return ret;
        else
            throw new IllegalArgumentException("No enum const " + LoginErrorMsgEnum.class
                    + "." + key);
    }

    public static boolean isDefined(String value){
        if(map.containsKey(value)) {
            return true;
        }else{
            return false;
        }
    }
}
